﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Text.RegularExpressions;

namespace CFScript
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Parameter
    {
        string name;
        string value;
        bool isRequired;
        bool isEvaluable;

        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public string OriginalValue
        {
            get { return this.value; }
            set { this.value = value; }
        }

        public Parameter(string name, string value, bool isEvaluable) : this(name, value, isEvaluable, false) { } 

        public Parameter(string name, string value) : this(name, value, false, false) { }

        public Parameter(string name, string value, bool isEvaluable, bool isRequired)
        {
            this.name = name;
            this.value = value;
            this.isEvaluable = isEvaluable;
            this.isRequired = isRequired;
        }

        public string GetValue(CFScript context)
        {
            if (this.isEvaluable)
            {
                return context.ExpandValue(this.value);
            }
            else
            {
                return this.value;
            }
        }

        public bool GetValueAsBoolean()
        {
            bool result = false;

            try
            {
                result = bool.Parse(this.value);
            }
            catch (Exception)
            {
                result = false;
            }

            return result;
        }

        public int GetValueAsInteger()
        {
            int result = 0;

            try
            {
                result = int.Parse(this.value);
            }
            catch
            {
            }

            return result;
        }
    }
}
